CC = g++
LEX=flex
PARSER=bison
CFLAGS=
LFLAGS=
PFLAGS=-d -v
NUM_OF_TESTCASES=22

all: group dirgen Micro

compiler: dirgen Micro

dirgen:
	mkdir -p generated
	mkdir -p build
	mkdir -p lib
	mkdir -p src
	
group:
	echo "Yuchen Huang"

generated/parser.tab.c generated/parser.tab.h: src/parser.y
	$(PARSER) $(PFLAGS) src/parser.y
	mv parser.tab.c generated/parser.tab.c
	mv parser.tab.h generated/parser.tab.h

generated/lex.yy.c: src/scanner.l
	$(LEX) $(LFLAGS) src/scanner.l
	mv lex.yy.c generated/lex.yy.c
	
Micro: generated/parser.tab.c generated/parser.tab.h generated/lex.yy.c
	$(CC) generated/lex.yy.c generated/parser.tab.c $(CFLAGS) -o Micro
	mv Micro build/Micro

clean:
	rm -f generated/* build/* *.o lex.yy.c parser.tab.h parser.tab.c Micro result.txt parser.output
	rm -rf generated build

ttest:	
	rm -f result.txt
	NUM=1
	while [[ $NUM -le $(NUM_OF_TESTCASES) ]]  
		do
			echo $NUM
			(( NUM = $NUM + 1 ))
	done
test:
	rm -f result.txt
	./build/Micro testcases/input/test1.micro 2>/dev/null
	./build/Micro testcases/input/test2.micro 2>/dev/null
	./build/Micro testcases/input/test3.micro 2>/dev/null
	./build/Micro testcases/input/test4.micro 2>/dev/null
	./build/Micro testcases/input/test5.micro 2>/dev/null
	./build/Micro testcases/input/test6.micro 2>/dev/null
	./build/Micro testcases/input/test7.micro 2>/dev/null
	./build/Micro testcases/input/test8.micro 2>/dev/null
	./build/Micro testcases/input/test9.micro 2>/dev/null
	./build/Micro testcases/input/test10.micro 2>/dev/null
	./build/Micro testcases/input/test11.micro 2>/dev/null
	./build/Micro testcases/input/test12.micro 2>/dev/null
	./build/Micro testcases/input/test13.micro 2>/dev/null
	./build/Micro testcases/input/test14.micro 2>/dev/null
	./build/Micro testcases/input/test15.micro 2>/dev/null
	./build/Micro testcases/input/test16.micro 2>/dev/null
	./build/Micro testcases/input/test17.micro 2>/dev/null
	./build/Micro testcases/input/test18.micro 2>/dev/null
	./build/Micro testcases/input/test19.micro 2>/dev/null
	./build/Micro testcases/input/test20.micro 2>/dev/null
	./build/Micro testcases/input/test21.micro 2>/dev/null
	./build/Micro testcases/input/test22.micro 2>/dev/null

